export default {
	namespaced:true,
	state:()=>{
		return {
			city:'定位中...'
		}
	},
	mutations:{
		initCityMut(state,cityName){
			state.city = cityName
		}
	},
	actions:{
		initLocAction(context){
			uni.getLocation({
				success: ({longitude,latitude}) => {
					console.log(longitude,latitude);
					uni.request({
						url:`https://restapi.amap.com/v3/geocode/regeo?key=814dd2cfdf48cdd065a6bf4d52003517&location=${longitude},${latitude}`,
						success: (res) => {
							// console.log(res);
							let {province,city} = res.data.regeocode.addressComponent
							let cityName = city.length?city:province
							context.commit('initCityMut',cityName)
						}
					})
				}
			})
		}
	}
}